package galaxy.auth.provider.config;

import galaxy.auth.provider.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport{

	@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("doc.html").addResourceLocations(
                "classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations(
                "classpath:/META-INF/resources/webjars/");
        super.addResourceHandlers(registry);
    }
	
	@Override
	public void addInterceptors(InterceptorRegistry registry)  {
		registry.addInterceptor(getTokenInterceptor()).addPathPatterns("/**")
			//排除未读消息，下载请求
			.excludePathPatterns("/getNoticeByUserId","/download/","/downloadOrderReprot/","/downloadAttach/","/zipDownOssFile/")
			//排除swagger请求
			.excludePathPatterns("/doc.html/**","/webjars/**","/swagger-resources/**");
	}
	
	@Bean
	public TokenInterceptor getTokenInterceptor() {
		return new TokenInterceptor();
	}
}
